﻿@model Models.Users

@{
    Layout = null;
    ViewData["Title"] = "个人资料";
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>@ViewData["Title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
        <style>
            select {
                height: 36px;
                -moz-appearance: none;
                -webkit-appearance: none;
                border-color: #e6e6e6;
                width: 100px;
                line-height: 25px;
                text-indent: 5px;
                background-color: transparent;
            }
        </style>
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
        <style>
            select {
                height: 36px;
                -moz-appearance: none;
                -webkit-appearance: none;
                border-color: #e6e6e6;
                width: 100px;
                line-height: 25px;
                text-indent: 5px;
                background-color: transparent;
            }
        </style>
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                @if (Model != null && Model.Id > 0) {
                    <div class="layui-card">
                        <div class="layui-card-header">@ViewData["Title"]</div>
                        <div class="layui-card-body" pad15>
                            <div class="layui-form" action="" lay-filter="">
                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">会员编号</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid">@Model.UserCode</div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">姓 名</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid">@Model.UserName</div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">身份证</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid">@Model.IdCard</div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">联系手机</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid">@Model.Phone</div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">等 级</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid">@Model.strLevel</div>
                                        </div>
                                    </div>
                                </div>

                                @if (Model.ParentId > 0) {
                                    <div class="layui-form-item">
                                        <div class="layui-col-lg6">
                                            <label class="layui-form-label">推荐人编号</label>
                                            <div class="layui-input-block">
                                                <div class="layui-form-mid">@ViewData["Parent"]</div>
                                            </div>
                                        </div>
                                    </div>
                                }

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">余 额</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid"><h2 style="color:#ca0e0e" id="divOverage" data-value="@Model.Overage">@Model.Overage.ToString("C")</h2></div>
                                            @if (ViewData["show"] != null && (bool)ViewData["show"]) {
                                                <button class="layui-btn layui-btn-normal layui-btn-radius  layui-btn-sm" lay-submit="" lay-filter="cashLog"><i class="layui-icon layui-icon-rmb layuiadmin-button-btn"></i> 提现</button>}
                                        </div>
                                    </div>
                                </div>
                                @if (ViewData["tips"] != null) {
                                    <div class="layui-form-item">
                                        <div class="layui-col-lg6">
                                            <label class="layui-form-label"></label>
                                            <div class="layui-input-block">
                                                <div class="layui-form-mid">@ViewData["tips"]</div>
                                            </div>
                                        </div>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>

                    <div class="layui-card">
                        <div class="layui-card-header">提现信息</div>
                        <div class="layui-card-body" pad15>
                            <div class="layui-form" action="" lay-filter="">
                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">提现方式</label>
                                        <div class="layui-input-block">
                                            <input type="hidden" asp-for="Cash.FirstOrDefault().Id" />
                                            @foreach (var m in (ViewData["cash"] as List<Models.ItemList>)) {
                                                @if (Model.Cash != null && Model.Cash.Count > 0) {
                                                    if ((int)Model.Cash.FirstOrDefault().CashType == m.value) {
                                                        <input type="radio" asp-for="Cash.FirstOrDefault().CashType" value="@m.value" title="@m.text" lay-filter="radio" checked>
                                                    } else {
                                                        <input type="radio" asp-for="Cash.FirstOrDefault().CashType" value="@m.value" title="@m.text" lay-filter="radio">
                                                    }
                                                } else {
                                                    <input type="radio" asp-for="Cash.FirstOrDefault().CashType" value="@m.value" title="@m.text" lay-filter="radio">
                                                }
                                            }
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        @if (Model.Cash != null && Model.Cash.Count > 0) {
                                            if (Model.Cash.FirstOrDefault().CashType == Code.CashType.银行卡) {
                                                <label class="layui-form-label" id="lblAccount">银行卡号</label>
                                            } else if (Model.Cash.FirstOrDefault().CashType == Code.CashType.支付宝) {
                                                <label class="layui-form-label" id="lblAccount">账 户</label>
                                            } else {
                                                <label class="layui-form-label" id="lblAccount">微信号</label>
                                            }
                                        } else {
                                            <label class="layui-form-label" id="Account">银行卡号</label>
                                        }
                                        <div class="layui-input-block">
                                            <input type="text" asp-for="Cash.FirstOrDefault().Account" lay-verify="required" placeholder="请输入您的银行卡号" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        @if (Model.Cash != null && Model.Cash.Count > 0) {
                                            if (Model.Cash.FirstOrDefault().CashType == Code.CashType.银行卡) {
                                                <label class="layui-form-label" id="Name">开户行</label>
                                            } else {
                                                <label class="layui-form-label" id="Name">姓 名</label>
                                            }
                                        } else {
                                            <label class="layui-form-label" id="Name">开户行</label>
                                        }
                                        <div class="layui-input-block">
                                            <input type="text" asp-for="Cash.FirstOrDefault().AccountName" lay-verify="required" placeholder="如：中国银行（广州香雪支行）" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>

                                @if (Model.Cash != null && Model.Cash.Count > 0) {
                                    if (Model.Cash.FirstOrDefault().CashType == Code.CashType.银行卡) {
                                        <div class="layui-form-item" id="divBank">
                                            <div class="layui-col-lg6">
                                                <label class="layui-form-label">收款户名</label>
                                                <div class="layui-input-block">
                                                    <input type="text" asp-for="Cash.FirstOrDefault().Bank" placeholder="请输入收款户名" autocomplete="off" class="layui-input" lay-verify="required" />
                                                </div>
                                            </div>
                                        </div>
                                    } else {
                                        <div class="layui-form-item" id="divBank" style="display:none;">
                                            <div class="layui-col-lg6">
                                                <label class="layui-form-label">收款户名</label>
                                                <div class="layui-input-block">
                                                    <input type="text" asp-for="Cash.FirstOrDefault().Bank" placeholder="" autocomplete="off" class="layui-input" lay-verify="" />
                                                </div>
                                            </div>
                                        </div>
                                    }
                                } else {
                                    <div class="layui-form-item" id="divBank">
                                        <div class="layui-col-lg6">
                                            <label class="layui-form-label">收款户名</label>
                                            <div class="layui-input-block">
                                                <input type="text" asp-for="Cash.FirstOrDefault().Bank" placeholder="请输入收款户名" autocomplete="off" class="layui-input" lay-verify="required" />
                                            </div>
                                        </div>
                                    </div>
                                }
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="cashinfo">保存提现信息</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-card">
                        <div class="layui-card-header">收货地址</div>
                        <div class="layui-card-body" pad15>
                            <div class="layui-form" action="" lay-filter="">
                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">收货人</label>
                                        <div class="layui-input-block">
                                            <input type="hidden" asp-for="ShippingAddress.FirstOrDefault().Id" />
                                            <input type="hidden" name="UsersId" value="@Model.Id" />
                                            <input type="text" asp-for="ShippingAddress.FirstOrDefault().Receiver" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">联系电话</label>
                                        <div class="layui-input-block">
                                            <input type="text" asp-for="ShippingAddress.FirstOrDefault().Phone" lay-verify="required|phone" placeholder="" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">省份城市</label>
                                        <div class="layui-input-block">
                                            <div class="layui-inline">
                                                <select asp-for="ShippingAddress.FirstOrDefault().ProvinceId" data-type="divCity" lay-filter="pro" lay-ignore lay-verify="select">
                                                    @foreach (var m in (ViewData["pro"] as List<Models.Area>)) {
                                                        @if (Model.ShippingAddress != null && Model.ShippingAddress.Count > 0) {
                                                            if ((int)Model.ShippingAddress.FirstOrDefault().ProvinceId == m.id) {
                                                                <option value="@m.id" selected>@m.name</option>
                                                            } else {
                                                                <option value="@m.id">@m.name</option>
                                                            }
                                                        } else {
                                                            <option value="@m.id">@m.name</option>
                                                        }
                                                    }
                                                </select>
                                                <i class="layui-edge" style="top:0; right:2%;"></i>
                                            </div>

                                            <div class="layui-inline" id="divCity">
                                                @if (Model.ShippingAddress != null && Model.ShippingAddress.Count > 0) {
                                                    @if (Model.ShippingAddress.FirstOrDefault().CityId > 0) {
                                                        <select asp-for="ShippingAddress.FirstOrDefault().CityId" data-type="divArea" lay-ignore lay-filter="pro" lay-verify="select">
                                                            @foreach (var m in (ViewData["city"] as List<Models.Area>)) {
                                                                @if (Model.ShippingAddress != null && Model.ShippingAddress.Count > 0) {
                                                                    if ((int)Model.ShippingAddress.FirstOrDefault().CityId == m.id) {
                                                                        <option value="@m.id" selected>@m.name</option>
                                                                    } else {
                                                                        <option value="@m.id">@m.name</option>
                                                                    }
                                                                } else {
                                                                    <option value="@m.id">@m.name</option>
                                                                }
                                                            }
                                                        </select>
                                                    }
                                                }
                                            </div>
                                            <div class="layui-inline" id="divArea">
                                                @if (Model.ShippingAddress != null && Model.ShippingAddress.Count > 0) {

                                                    @if (Model.ShippingAddress.FirstOrDefault().AreaId > 0) {
                                                        <select asp-for="ShippingAddress.FirstOrDefault().AreaId" data-type="" lay-ignore lay-filter="pro" lay-verify="select">
                                                            @foreach (var m in (ViewData["area"] as List<Models.Area>)) {
                                                                @if (Model.ShippingAddress != null && Model.ShippingAddress.Count > 0) {
                                                                    if ((int)Model.ShippingAddress.FirstOrDefault().AreaId == m.id) {
                                                                        <option value="@m.id" selected>@m.name</option>
                                                                    } else {
                                                                        <option value="@m.id">@m.name</option>
                                                                    }
                                                                } else {
                                                                    <option value="@m.id">@m.name</option>
                                                                }
                                                            }
                                                        </select>
                                                    }
                                                }
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">地 址</label>
                                        <div class="layui-input-block">
                                            <input type="text" asp-for="ShippingAddress.FirstOrDefault().Address" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="shipping">保存地址</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>

    <div class="layui-fluid" id="cash" style="display:none;">
        <div class="layui-row layui-col-space6">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-form" action="" lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">提现金额</label>
                                <div class="layui-input-inline"><input type="text" maxlength="20" id="price" name="price" placeholder="" lay-verify="" class="layui-input"></div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-input-block">
                                        <div class="layui-form-mid" style="width:200px;">每笔提现将收取 <i id="fee" style="color:#ca0e0e; font-size: 18px;"></i> 的手续费</div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">二级密码</label>
                                <div class="layui-input-inline"><input type="password" id="pwd" name="pwd" placeholder="" lay-verify="" class="layui-input"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form'], function () {
            var $ = layui.$
                , form = layui.form
                , cashInfo = 0;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            cashInfo = $('input[name="CashType"]:checked').val();

            if (cashInfo == undefined) {
                $("input[name='CashType']").get(0).click();

                form.render('radio');
            }

            form.on('radio(radio)', function (data) {
                if (data.value == 1) {
                    $('#lblAccount').text('银行卡号');
                    $('#Account').val('');
                    $('#Name').text('开户行');
                    $('#AccountName').val('');
                    $('#divBank').show();
                    $('#Bank').attr('lay-verify', 'required');
                }
                else if (data.value == 2) {
                    $('#lblAccount').text('账 户');
                    $('#Account').val('');
                    $('#Name').text('姓  名');
                    $('#AccountName').val('');
                    $('#divBank').hide();
                    $('#Bank').attr('lay-verify', '');
                }
                else {
                    $('#lblAccount').text('微信号');
                    $('#Account').val('');
                    $('#Name').text('姓  名');
                    $('#AccountName').val('');
                    $('#divBank').hide();
                    $('#Bank').attr('lay-verify', '');
                }
            });

            form.on('submit(cashinfo)', function (data) {
                if (data.field.CashType != 1) {
                    data.field.Bank = '';
                }

                $.ajax({
                    url: '@Url.Action("savecashinfo", "api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data.field),
                    type:'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    window.parent.tools.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function () {

                    });
                });
            });

            form.verify({
                select: function (value, item) {
                    if (value.length === 0) {
                        return '请选择城市省份';
                    }

                    if (value === 0) {
                        return '请选择城市省份';
                    }
                }
            });

            form.on('submit(cashLog)', function () {
                $.ajax({
                    url: '@Url.Action("IsSetSecondaryPwd", "api")',
                    dataType: 'json',
                    contentType: 'application/json'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    if (res.code == 0) {
                        $('#fee').text(res.data.strValue);
                        $('#fee').attr('data-value', res.data.value);
                        $('#fee').attr('data-overage', res.data.Overage);
                        var multiple = res.data.multiple;

                        if (!res.data) {
                            window.parent.tools.msg("未设置二级密码或未填写提现信息");
                            return;
                        }

                        window.parent.tools.open($('#cash').html(), '提现', ['确定', '取消'], ['420px'], ['pwd', 'price'], function (index,values) {
                            var secondaryPwd = values.pwd
                                , price = values.price
                                , fee = res.data.value;

                            if (price % multiple != 0) {
                                window.parent.tools.msg('输入的金额非' + multiple + '的倍数，请重新输入');
                                    return;
                                }

                                $.ajax({
                                    url: '@Url.Action("SaveCashLog", "api")',
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    data: JSON.stringify({ secondaryPwd: secondaryPwd, price: price, fee: fee }),
                                    type: 'post'
                                }).fail(function (jqXHR, textStatus, errorThrown) {
                                    window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                                }).done(function (res) {
                                    window.parent.tools.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function () {
                                        if (res.code == 0) {
                                            $('#divOverage').text(res.data);
                                            window.parent.tools.closeAll();
                                        }
                                    });
                                });
                        })
                        @*var layerIndex = layer.open({
                            type: 1,
                            title: '提现',
                            close: false,
                            shade: 0.8,
                            area: ['420px'],
                            content: $('#cash'),
                            btn: ['确定','取消'],
                            btnAlign: 'c',
                            yes: function () {
                                var secondaryPwd = '', price = 0, fee = '';

                                secondaryPwd = $('#pwd').val();
                                price = $('#price').val();
                                fee = $('#fee').attr('data-value');

                                if (price % multiple != 0) {
                                    layer.msg('输入的金额非' + multiple + '的倍数，请重新输入');
                                    return;
                                }

                                $.ajax({
                                    url: '@Url.Action("SaveCashLog", "api")',
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    data: JSON.stringify({ secondaryPwd: secondaryPwd, price: price, fee: fee }),
                                    type: 'post'
                                }).fail(function (jqXHR, textStatus, errorThrown) {
                                    layer.alert(errorThrown, { icon: 2, title: textStatus });
                                }).done(function (res) {
                                    layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function () {
                                        if (res.code == 0) {
                                            $('#divOverage').text(res.data);
                                            layer.closeAll();
                                        }
                                    });
                                });
                            }
                        });*@
                    } else {
                        window.parent.tools.msg(res.message);
                    }
                });
            });

            form.on('submit(shipping)', function (data) {
                $.ajax({
                    url: '@Url.Action("saveaddresss", "api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data.field),
                    type:'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function () {

                    });
                });
            });

            var action = {
                area: function (param) {
                    $.ajax({
                        url: '@Url.Action("GetCityList", "api")?remove=0&id=' + param.id,
                        dataType: 'json',
                        contentType: 'application/json',
                        type:'get'
                    }).fail(function (jqXHR, textStatus, errorThrown) {
                        layer.alert(errorThrown, { icon: 2, title: textStatus });
                    }).done(function (res) {
                        var html = ''
                            , $elem = $('#' + param.type)
                            , dataType = ''
                            , selName = '';

                        if (param.type == 'divCity') {
                            selName = 'CityId';
                            dataType = 'divArea'

                            $('#divCity').html('');
                            $('#divArea').html('');
                        } else {
                            selName = 'AreaId';
                        }

                        if (res.data && res.data.length > 0) {
                            html = '<select name="' + selName + '"  lay-ignore id="' + selName + '" data-type="' + dataType + '" lay-verify=""  lay-filter="pro" lay-verify="select">';

                            res.data.forEach(function (item) {
                                if (item.id == 0) {
                                    html += '<option value=' + item.id + ' selected>' + item.name + '</option>';
                                }
                                else {
                                    html += '<option value=' + item.id + '>' + item.name + '</option>';
                                }
                            });

                            html += '</select>';
                        }

                        $elem.html(html);

                        //form.render('select');
                    });
                }
            };

            @*form.on('select(pro)', function (data) {
                var $elem = $('#' + data.elem.id)
                    , event = $elem.attr('data-type');

                action.area ? action.area({'id':data.value,'type':event}) : '';
            });*@

            $(document).on('change', 'select[lay-filter="pro"]', function () {
                var val = this.value
                    , event = $(this).attr('data-type');

                action.area ? action.area({ 'id': val, 'type': event }) : '';
            });
        });
    </script>
</body>
</html>
